﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MS_UI;



namespace MS_UI
{
    public partial class FrmHardwareConfig : Form
    {
        public FrmHardwareConfig()
        {
            InitializeComponent();
        }

        #region 打开窗体
        private void OpenWindow(Form Frm)
        {

            //不能为顶级窗体
            Frm.TopLevel = false;
            //窗体边框样式
            Frm.FormBorderStyle = FormBorderStyle.None;
            //指定位置和控件停靠方式
            Frm.Dock = DockStyle.Fill;

            //获取或控制控件的父容器
            Frm.Parent = this.mainPanel;
            //打开窗体
            Frm.Show();


        }
        #endregion



        #region 关闭窗体
        private bool CloseWindow(string FrmName)
        {

            foreach (Control ct in this.mainPanel.Controls)
            {
                if (ct is Form)
                {

                    Form Frm = (Form)ct;

                    if (Frm.Name == FrmName)
                    {
                        return true;
                    }
                    else
                    {

                        Frm.Close();
                    }

                }
            }
            return false;
        }




        #endregion


        private void btn_ProtocolConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmProtocolConfig") == false)
            {

                OpenWindow(new FrmProtocolConfig());

            }
        }



        private void btn_IOVarConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmIOVarConfig") == false)
            {

                OpenWindow(new FrmIOVarConfig());
              
            }
        }

        private void btn_PararsetConfig_Click(object sender, EventArgs e)
        {
            if (CloseWindow("FrmPararsetConfig") == false)
            {

                OpenWindow(new FrmPararsetConfig());

            }
        }

        
    }
}
